home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / tvg110a.zip / B7DEMSRC.ZIP / TVDEMO.PAS < prev   
Pascal/Delphi Source File  |  1993-02-22  |  20KB  |  714 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Vision Demo                            }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. program TVDemo;
  9.  
  10. {$X+,S-}
  11. {$M 16384,8192,655360}
  12.  
  13. { Turbo Vision demo program. This program uses many of the Turbo
  14.   Vision standard and demo units, including:
  15.  
  16.     StdDlg    - Open file browser, change directory tree.
  17.     MsgBox    - Simple dialog to display messages.
  18.     ColorSel  - Color customization.
  19.     Gadgets   - Shows system time and available heap space.
  20.     AsciiTab  - ASCII table.
  21.     Calendar  - View a month at a time
  22.     Calc      - Desktop calculator.
  23.     HelpFile  - Context sensitive help.
  24.     MouseDlg  - Mouse options dialog.
  25.     Puzzle    - Simple brain puzzle.
  26.     Editors   - Text Editor object.
  27.  
  28.   And of course this program includes many standard Turbo Vision
  29.   objects and behaviors (menubar, desktop, status line, dialog boxes,
  30.   mouse support, window resize/move/tile/cascade).
  31. }
  32.  
  33. uses
  34.   TvGraph, TVGDefs, TVGWhiz, Styx,                     { ** TVGRAPH ** }
  35.   Dos, Objects, Drivers, Memory, Views, Menus, Dialogs, StdDlg, HistList,
  36.   MsgBox, App, DemoCmds, Gadgets, Puzzle, Calendar, AsciiTab, Calc,
  37.   HelpFile, DemoHelp, ColorSel, MouseDlg, Editors;
  38.  
  39. { If you get a FILE NOT FOUND error when compiling this program
  40.   from a DOS IDE, change to the \BP\EXAMPLES\DOS\TVDEMO directory
  41.   (use File|Change dir).
  42.  
  43.   This will enable the compiler to find all of the units used by
  44.   this program.
  45. }
  46.  
  47. const
  48.   HeapSize = 48 * (1024 div 16);  { Save 48k heap for main program }
  49.  
  50.   { Desktop file signature information }
  51.   SignatureLen = 21;
  52.   DSKSignature : string[SignatureLen] = 'TV Demo Desktop File'#26;
  53.  
  54. var
  55.   ClipWindow: PEditWindow;
  56.  
  57. type
  58.  
  59.   { TTVDemo }
  60.  
  61.   PTVDemo = ^TTVDemo;
  62.   TTVDemo = object(TVGApp)                   { ** TVGRAPH ** }
  63.     Clock: PClockView;
  64.     Heap: PHeapView;
  65.     constructor Init;
  66.     procedure FileOpen(WildCard: PathStr);
  67.     function OpenEditor(FileName: FNameStr; Visible: Boolean): PEditWindow;
  68.     procedure GetEvent(var Event: TEvent); virtual;
  69.     function GetPalette: PPalette; virtual;
  70.     procedure HandleEvent(var Event: TEvent); virtual;
  71.     procedure Idle; virtual;
  72.     procedure InitMenuBar; virtual;
  73.     procedure InitStatusLine; virtual;
  74.     procedure LoadDesktop(var S: TStream);
  75.     procedure OutOfMemory; virtual;
  76.     procedure StoreDesktop(var S: TStream);
  77.   end;
  78.  
  79. { CalcHelpName }
  80.  
  81. function CalcHelpName: PathStr;
  82. var
  83.   EXEName: PathStr;
  84.   Dir: DirStr;
  85.   Name: NameStr;
  86.   Ext: ExtStr;
  87. begin
  88.   if Lo(DosVersion) >= 3 then EXEName := ParamStr(0)
  89.   else EXEName := FSearch('TVDEMO.EXE', GetEnv('PATH'));
  90.   FSplit(EXEName, Dir, Name, Ext);
  91.   if Dir[Length(Dir)] = '\' then Dec(Dir[0]);
  92.   CalcHelpName := FSearch('DEMOHELP.HLP', Dir);
  93. end;
  94.  
  95. function CreateFindDialog: PDialog;
  96. var
  97.   D: PDialog;
  98.   Control: PView;
  99.   R: TRect;
  100. begin
  101.   R.Assign(0, 0, 38, 12);
  102.   D := New(PDialog, Init(R, 'Find'));
  103.   with D^ do
  104.   begin
  105.     Options := Options or ofCentered;
  106.  
  107.     R.Assign(3, 3, 32, 4);
  108.     Control := New(PInputLine, Init(R, 80));
  109.     Insert(Control);
  110.     R.Assign(2, 2, 15, 3);
  111.     Insert(New(PLabel, Init(R, '~T~ext to find', Control)));
  112.     R.Assign(32, 3, 35, 4);
  113.     Insert(New(PHistory, Init(R, PInputLine(Control), 10)));
  114.  
  115.     R.Assign(3, 5, 35, 7);
  116.     Insert(New(PCheckBoxes, Init(R,
  117.       NewSItem('~C~ase sensitive',
  118.       NewSItem('~W~hole words only', nil)))));
  119.  
  120.     R.Assign(14, 9, 24, 11);
  121.     Insert(New(PButton, Init(R, 'O~K~', cmOk, bfDefault)));
  122.     Inc(R.A.X, 12); Inc(R.B.X, 12);
  123.     Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
  124.  
  125.     SelectNext(False);
  126.   end;
  127.   CreateFindDialog := D;
  128. end;
  129.  
  130. function CreateReplaceDialog: PDialog;
  131. var
  132.   D: PDialog;
  133.   Control: PView;
  134.   R: TRect;
  135. begin
  136.   R.Assign(0, 0, 40, 16);
  137.   D := New(PDialog, Init(R, 'Replace'));
  138.   with D^ do
  139.   begin
  140.     Options := Options or ofCentered;
  141.  
  142.     R.Assign(3, 3, 34, 4);
  143.     Control := New(PInputLine, Init(R, 80));
  144.     Insert(Control);
  145.     R.Assign(2, 2, 15, 3);
  146.     Insert(New(PLabel, Init(R, '~T~ext to find', Control)));
  147.     R.Assign(34, 3, 37, 4);
  148.     Insert(New(PHistory, Init(R, PInputLine(Control), 10)));
  149.  
  150.     R.Assign(3, 6, 34, 7);
  151.     Control := New(PInputLine, Init(R, 80));
  152.     Insert(Control);
  153.     R.Assign(2, 5, 12, 6);
  154.     Insert(New(PLabel, Init(R, '~N~ew text', Control)));
  155.     R.Assign(34, 6, 37, 7);
  156.     Insert(New(PHistory, Init(R, PInputLine(Control), 11)));
  157.  
  158.     R.Assign(3, 8, 37, 12);
  159.     Insert(New(PCheckBoxes, Init(R,
  160.       NewSItem('~C~ase sensitive',
  161.       NewSItem('~W~hole words only',
  162.       NewSItem('~P~rompt on replace',
  163.       NewSItem('~R~eplace all', nil)))))));
  164.  
  165.     R.Assign(17, 13, 27, 15);
  166.     Insert(New(PButton, Init(R, 'O~K~', cmOk, bfDefault)));
  167.     R.Assign(28, 13, 38, 15);
  168.     Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
  169.  
  170.     SelectNext(False);
  171.   end;
  172.   CreateReplaceDialog := D;
  173. end;
  174.  
  175. function DoEditDialog(Dialog: Integer; Info: Pointer): Word; far;
  176. var
  177.   R: TRect;
  178.   T: TPoint;
  179. begin
  180.   case Dialog of
  181.     edOutOfMemory:
  182.       DoEditDialog := MessageBox('Not enough memory for this operation.',
  183.         nil, mfError + mfOkButton);
  184.     edReadError:
  185.       DoEditDialog := MessageBox('Error reading file %s.',
  186.         @Info, mfError + mfOkButton);
  187.     edWriteError:
  188.       DoEditDialog := MessageBox('Error writing file %s.',
  189.         @Info, mfError + mfOkButton);
  190.     edCreateError:
  191.       DoEditDialog := MessageBox('Error creating file %s.',
  192.         @Info, mfError + mfOkButton);
  193.     edSaveModify:
  194.       DoEditDialog := MessageBox('%s has been modified. Save?',
  195.         @Info, mfInformation + mfYesNoCancel);
  196.     edSaveUntitled:
  197.       DoEditDialog := MessageBox('Save untitled file?',
  198.         nil, mfInformation + mfYesNoCancel);
  199.     edSaveAs:
  200.       DoEditDialog := Application^.ExecuteDialog(New(PFileDialog, Init('*.*',
  201.         'Save file as', '~N~ame', fdOkButton, 101)), Info);
  202.     edFind:
  203.       DoEditDialog := Application^.ExecuteDialog(CreateFindDialog, Info);
  204.     edSearchFailed:
  205.       DoEditDialog := MessageBox('Search string not found.',
  206.         nil, mfError + mfOkButton);
  207.     edReplace:
  208.       DoEditDialog := Application^.ExecuteDialog(CreateReplaceDialog, Info);
  209.     edReplacePrompt:
  210.       begin
  211.         { Avoid placing the dialog on the same line as the cursor }
  212.         R.Assign(0, 1, 40, 8);
  213.         R.Move((Desktop^.Size.X - R.B.X) div 2, 0);
  214.         Desktop^.MakeGlobal(R.B, T);
  215.         Inc(T.Y);
  216.         if TPoint(Info).Y <= T.Y then
  217.           R.Move(0, Desktop^.Size.Y - R.B.Y - 2);
  218.         DoEditDialog := MessageBoxRect(R, 'Replace this occurence?',
  219.           nil, mfYesNoCancel + mfInformation);
  220.       end;
  221.   end;
  222. end;
  223.  
  224. { TTVDemo }
  225. constructor TTVDemo.Init;
  226. var
  227.   R: TRect;
  228.   I: Integer;
  229.   FileName: PathStr;
  230. begin
  231.   BGIPath:='';
  232.   MaxHeapSize := HeapSize;
  233.   inherited Init;
  234.   RegisterObjects;
  235.   RegisterViews;
  236.   RegisterMenus;
  237.   RegisterDialogs;
  238.   RegisterApp;
  239.   RegisterHelpFile;
  240.   RegisterPuzzle;
  241.   RegisterCalendar;
  242.   RegisterAsciiTab;
  243.   RegisterCalc;
  244.   RegisterEditors;
  245.   RegisterStyx;  { ** TVGRAPH ** }
  246.  
  247.   { Initialize demo gadgets }
  248.  
  249.   GetExtent(R);
  250.   R.A.X := R.B.X - 9; R.B.Y := R.A.Y + 1;
  251.   Clock := New(PClockView, Init(R));
  252.   Insert(Clock);
  253.  
  254.   GetExtent(R);
  255.   Dec(R.B.X);
  256.   R.A.X := R.B.X - 9; R.A.Y := R.B.Y - 1;
  257.   Heap := New(PHeapView, Init(R));
  258.   Insert(Heap);
  259.  
  260.   DisableCommands([cmSave, cmSaveAs, cmCut, cmCopy, cmPaste, cmClear,
  261.     cmUndo, cmFind, cmReplace, cmSearchAgain, cmCloseAll]);
  262.   EditorDialog := DoEditDialog;
  263.   ClipWindow := OpenEditor('', False);
  264.   if ClipWindow <> nil then
  265.   begin
  266.     Clipboard := ClipWindow^.Editor;
  267.     Clipboard^.CanUndo := False;
  268.   end;
  269.  
  270.   for I := 1 to ParamCount do
  271.   begin
  272.     FileName := ParamStr(I);
  273.     if FileName[Length(FileName)] = '\' then
  274.       FileName := FileName + '*.*';
  275.     if (Pos